package org.gingresosapi.persistencia;

import org.gingresosapi.beans.Remolquestraspaso;
import java.sql.Date; 
import org.gingresosapi.beans.*;
import org.gingresosapi.controller.*;
import java.io.Serializable;
import java.util.List;
import java.util.ArrayList;
import java.util.*;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.util.Map;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Map;
 import javax.sql.DataSource;
import org.gingresosapi.generales.Mensajeria;
import org.gingresosapi.generales.DataGManager;


/**
*
* @author
*/

public class RemolquestraspasoPersistencia implements Serializable {
private static final long serialVersionUID = 1L;
public static Exception excepcion;
public static boolean esMensaje = false;
public static Connection con = null;
public static java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/gingresosapi/properties/mensajes");
static DataGManager dataGManager;
static List<Remolquestraspaso> list;

public RemolquestraspasoPersistencia(){
         esMensaje =false;
}


/**
*
* insert()
*/

public static boolean insert (Remolquestraspaso remolquestraspaso ) {
  excepcion = null;
  try {
      esMensaje =false;
   
   
   

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pinsert = null;
      String sql = "insert into remolquestraspaso(idnumeraciontraspaso,idremolque,placa,idrecibo,idold,tipoidold,id,tipoid,activo,idmunicipio,fechatraspaso,fecha,username)  values(?,?,?,?,?,?,?,?,?,?,?,?,?)";
      pinsert = con.prepareStatement(sql);
              pinsert.setInt(1,remolquestraspaso.getIdnumeraciontraspaso());
        pinsert.setLong(2,remolquestraspaso.getIdremolque());
        pinsert.setString(3,remolquestraspaso.getPlaca());
        pinsert.setInt(4,remolquestraspaso.getIdrecibo());
        pinsert.setString(5,remolquestraspaso.getIdold());
        pinsert.setString(6,remolquestraspaso.getTipoidold());
        pinsert.setString(7,remolquestraspaso.getId());
        pinsert.setString(8,remolquestraspaso.getTipoid());
        pinsert.setString(9,remolquestraspaso.getActivo());
        pinsert.setString(10,remolquestraspaso.getIdmunicipio());
        pinsert.setDate(11,remolquestraspaso.getFechatraspaso());
        pinsert.setDate(12,remolquestraspaso.getFecha());
        pinsert.setString(13,remolquestraspaso.getUsername());
      int filas= pinsert.executeUpdate();
      pinsert.close();
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
 }


/**
*
* update()
*/

public static boolean update(Remolquestraspaso remolquestraspaso ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update remolquestraspaso set  idnumeraciontraspaso=?, idremolque=?, placa=?, idrecibo=?, idold=?, tipoidold=?, id=?, tipoid=?, activo=?, idmunicipio=?, fechatraspaso=?, fecha=?, username=?  where  idnumeraciontraspaso ='"+remolquestraspaso.getIdnumeraciontraspaso()+"' and  idmunicipio ='"+remolquestraspaso.getIdmunicipio()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setInt(1,remolquestraspaso.getIdnumeraciontraspaso());
pupdate.setLong(2,remolquestraspaso.getIdremolque());
pupdate.setString(3,remolquestraspaso.getPlaca());
pupdate.setInt(4,remolquestraspaso.getIdrecibo());
pupdate.setString(5,remolquestraspaso.getIdold());
pupdate.setString(6,remolquestraspaso.getTipoidold());
pupdate.setString(7,remolquestraspaso.getId());
pupdate.setString(8,remolquestraspaso.getTipoid());
pupdate.setString(9,remolquestraspaso.getActivo());
pupdate.setString(10,remolquestraspaso.getIdmunicipio());
pupdate.setDate(11,remolquestraspaso.getFechatraspaso());
pupdate.setDate(12,remolquestraspaso.getFecha());
pupdate.setString(13,remolquestraspaso.getUsername());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* update()
*/

public static boolean update(String sqlupdate ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update  remolquestraspaso set " + sqlupdate +"";
      pupdate= con.prepareStatement(sql);
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* updatePrimaryKey()
*/

public static boolean updatePrimaryKey(Remolquestraspaso remolquestraspaso_old , Remolquestraspaso remolquestraspaso) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update remolquestraspaso set  idnumeraciontraspaso=? ,  idmunicipio=?  where  idnumeraciontraspaso ='"+remolquestraspaso_old.getIdnumeraciontraspaso()+"' and  idmunicipio ='"+remolquestraspaso_old.getIdmunicipio()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setInt(1,remolquestraspaso.getIdnumeraciontraspaso());pupdate.setString(10,remolquestraspaso.getIdmunicipio());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(Remolquestraspaso remolquestraspaso ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from remolquestraspaso  where  idnumeraciontraspaso = ? and  idmunicipio = ?  ";
      pdelete= con.prepareStatement(sql);
      pdelete.setInt(1,remolquestraspaso.getIdnumeraciontraspaso());
pdelete.setString(10,remolquestraspaso.getIdmunicipio());
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(String sqldelete ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from remolquestraspaso where " + sqldelete +"";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* deleteAll()
*/

public static boolean deleteAll() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from remolquestraspaso  ";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodeleteall"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* exists()
*/



public static boolean exists(Remolquestraspaso remolquestraspaso) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      String sql = "select * from remolquestraspaso where idnumeraciontraspaso='"+remolquestraspaso.getIdnumeraciontraspaso()+"' and idmunicipio='"+remolquestraspaso.getIdmunicipio()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolquestraspaso" +" " + bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return false;
   }
    rs.close();
    psquery.close();
 return true;
} catch (Exception ex) {
      excepcion = ex;
}
  return false;
}


/**
*
* findByPrimaryKey()
*/



public static Remolquestraspaso findByPrimaryKey(Remolquestraspaso remolquestraspaso) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
      String sql = "select * from remolquestraspaso where idnumeraciontraspaso='"+remolquestraspaso.getIdnumeraciontraspaso()+"' and idmunicipio='"+remolquestraspaso.getIdmunicipio()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolquestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
            
            
            remolquestraspaso.setIdnumeraciontraspaso(rs.getInt("idnumeraciontraspaso"));
remolquestraspaso.setIdremolque(rs.getLong("idremolque"));
remolquestraspaso.setPlaca(rs.getString("placa"));
remolquestraspaso.setIdrecibo(rs.getInt("idrecibo"));
remolquestraspaso.setIdold(rs.getString("idold"));
remolquestraspaso.setTipoidold(rs.getString("tipoidold"));
remolquestraspaso.setId(rs.getString("id"));
remolquestraspaso.setTipoid(rs.getString("tipoid"));
remolquestraspaso.setActivo(rs.getString("activo"));
remolquestraspaso.setIdmunicipio(rs.getString("idmunicipio"));
remolquestraspaso.setFechatraspaso(rs.getDate("fechatraspaso"));
remolquestraspaso.setFecha(rs.getDate("fecha"));
remolquestraspaso.setUsername(rs.getString("username"));
    }
    rs.close();
    psquery.close();
 return remolquestraspaso;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdnumeraciontraspaso()
*/

public static List<Remolquestraspaso> findByIdnumeraciontraspaso(Remolquestraspaso remolquestraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Remolquestraspaso>();
      String sql = "select * from remolquestraspaso where idnumeraciontraspaso='"+remolquestraspaso.getIdnumeraciontraspaso()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolquestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Remolquestraspaso remolquestraspaso2 = new Remolquestraspaso(
         rs.getInt("idnumeraciontraspaso"),rs.getLong("idremolque"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getString("idold"),rs.getString("tipoidold"),rs.getString("id"),rs.getString("tipoid"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fechatraspaso"),rs.getDate("fecha"),rs.getString("username"));
            
            
       list.add(remolquestraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdremolque()
*/

public static List<Remolquestraspaso> findByIdremolque(Remolquestraspaso remolquestraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Remolquestraspaso>();
      String sql = "select * from remolquestraspaso where idremolque='"+remolquestraspaso.getIdremolque()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolquestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Remolquestraspaso remolquestraspaso2 = new Remolquestraspaso(
         rs.getInt("idnumeraciontraspaso"),rs.getLong("idremolque"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getString("idold"),rs.getString("tipoidold"),rs.getString("id"),rs.getString("tipoid"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fechatraspaso"),rs.getDate("fecha"),rs.getString("username"));
            
            
       list.add(remolquestraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByPlaca()
*/

public static List<Remolquestraspaso> findByPlaca(Remolquestraspaso remolquestraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Remolquestraspaso>();
      String sql = "select * from remolquestraspaso where placa='"+remolquestraspaso.getPlaca()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolquestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Remolquestraspaso remolquestraspaso2 = new Remolquestraspaso(
         rs.getInt("idnumeraciontraspaso"),rs.getLong("idremolque"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getString("idold"),rs.getString("tipoidold"),rs.getString("id"),rs.getString("tipoid"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fechatraspaso"),rs.getDate("fecha"),rs.getString("username"));
            
            
       list.add(remolquestraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdrecibo()
*/

public static List<Remolquestraspaso> findByIdrecibo(Remolquestraspaso remolquestraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Remolquestraspaso>();
      String sql = "select * from remolquestraspaso where idrecibo='"+remolquestraspaso.getIdrecibo()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolquestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Remolquestraspaso remolquestraspaso2 = new Remolquestraspaso(
         rs.getInt("idnumeraciontraspaso"),rs.getLong("idremolque"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getString("idold"),rs.getString("tipoidold"),rs.getString("id"),rs.getString("tipoid"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fechatraspaso"),rs.getDate("fecha"),rs.getString("username"));
            
            
       list.add(remolquestraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdold()
*/

public static List<Remolquestraspaso> findByIdold(Remolquestraspaso remolquestraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Remolquestraspaso>();
      String sql = "select * from remolquestraspaso where idold='"+remolquestraspaso.getIdold()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolquestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Remolquestraspaso remolquestraspaso2 = new Remolquestraspaso(
         rs.getInt("idnumeraciontraspaso"),rs.getLong("idremolque"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getString("idold"),rs.getString("tipoidold"),rs.getString("id"),rs.getString("tipoid"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fechatraspaso"),rs.getDate("fecha"),rs.getString("username"));
            
            
       list.add(remolquestraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByTipoidold()
*/

public static List<Remolquestraspaso> findByTipoidold(Remolquestraspaso remolquestraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Remolquestraspaso>();
      String sql = "select * from remolquestraspaso where tipoidold='"+remolquestraspaso.getTipoidold()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolquestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Remolquestraspaso remolquestraspaso2 = new Remolquestraspaso(
         rs.getInt("idnumeraciontraspaso"),rs.getLong("idremolque"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getString("idold"),rs.getString("tipoidold"),rs.getString("id"),rs.getString("tipoid"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fechatraspaso"),rs.getDate("fecha"),rs.getString("username"));
            
            
       list.add(remolquestraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findById()
*/

public static List<Remolquestraspaso> findById(Remolquestraspaso remolquestraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Remolquestraspaso>();
      String sql = "select * from remolquestraspaso where id='"+remolquestraspaso.getId()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolquestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Remolquestraspaso remolquestraspaso2 = new Remolquestraspaso(
         rs.getInt("idnumeraciontraspaso"),rs.getLong("idremolque"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getString("idold"),rs.getString("tipoidold"),rs.getString("id"),rs.getString("tipoid"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fechatraspaso"),rs.getDate("fecha"),rs.getString("username"));
            
            
       list.add(remolquestraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByTipoid()
*/

public static List<Remolquestraspaso> findByTipoid(Remolquestraspaso remolquestraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Remolquestraspaso>();
      String sql = "select * from remolquestraspaso where tipoid='"+remolquestraspaso.getTipoid()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolquestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Remolquestraspaso remolquestraspaso2 = new Remolquestraspaso(
         rs.getInt("idnumeraciontraspaso"),rs.getLong("idremolque"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getString("idold"),rs.getString("tipoidold"),rs.getString("id"),rs.getString("tipoid"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fechatraspaso"),rs.getDate("fecha"),rs.getString("username"));
            
            
       list.add(remolquestraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByActivo()
*/

public static List<Remolquestraspaso> findByActivo(Remolquestraspaso remolquestraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Remolquestraspaso>();
      String sql = "select * from remolquestraspaso where activo='"+remolquestraspaso.getActivo()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolquestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Remolquestraspaso remolquestraspaso2 = new Remolquestraspaso(
         rs.getInt("idnumeraciontraspaso"),rs.getLong("idremolque"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getString("idold"),rs.getString("tipoidold"),rs.getString("id"),rs.getString("tipoid"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fechatraspaso"),rs.getDate("fecha"),rs.getString("username"));
            
            
       list.add(remolquestraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdmunicipio()
*/

public static List<Remolquestraspaso> findByIdmunicipio(Remolquestraspaso remolquestraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Remolquestraspaso>();
      String sql = "select * from remolquestraspaso where idmunicipio='"+remolquestraspaso.getIdmunicipio()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolquestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Remolquestraspaso remolquestraspaso2 = new Remolquestraspaso(
         rs.getInt("idnumeraciontraspaso"),rs.getLong("idremolque"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getString("idold"),rs.getString("tipoidold"),rs.getString("id"),rs.getString("tipoid"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fechatraspaso"),rs.getDate("fecha"),rs.getString("username"));
            
            
       list.add(remolquestraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByFechatraspaso()
*/

public static List<Remolquestraspaso> findByFechatraspaso(Remolquestraspaso remolquestraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Remolquestraspaso>();
      String sql = "select * from remolquestraspaso where fechatraspaso='"+remolquestraspaso.getFechatraspaso()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolquestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Remolquestraspaso remolquestraspaso2 = new Remolquestraspaso(
         rs.getInt("idnumeraciontraspaso"),rs.getLong("idremolque"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getString("idold"),rs.getString("tipoidold"),rs.getString("id"),rs.getString("tipoid"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fechatraspaso"),rs.getDate("fecha"),rs.getString("username"));
            
            
       list.add(remolquestraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByFecha()
*/

public static List<Remolquestraspaso> findByFecha(Remolquestraspaso remolquestraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Remolquestraspaso>();
      String sql = "select * from remolquestraspaso where fecha='"+remolquestraspaso.getFecha()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolquestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Remolquestraspaso remolquestraspaso2 = new Remolquestraspaso(
         rs.getInt("idnumeraciontraspaso"),rs.getLong("idremolque"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getString("idold"),rs.getString("tipoidold"),rs.getString("id"),rs.getString("tipoid"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fechatraspaso"),rs.getDate("fecha"),rs.getString("username"));
            
            
       list.add(remolquestraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByUsername()
*/

public static List<Remolquestraspaso> findByUsername(Remolquestraspaso remolquestraspaso,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Remolquestraspaso>();
      String sql = "select * from remolquestraspaso where username='"+remolquestraspaso.getUsername()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolquestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Remolquestraspaso remolquestraspaso2 = new Remolquestraspaso(
         rs.getInt("idnumeraciontraspaso"),rs.getLong("idremolque"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getString("idold"),rs.getString("tipoidold"),rs.getString("id"),rs.getString("tipoid"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fechatraspaso"),rs.getDate("fecha"),rs.getString("username"));
            
            
       list.add(remolquestraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* locateByParameters()
*/

public static List<Remolquestraspaso> locateByParameters(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Remolquestraspaso>();
  String sql = "select * from remolquestraspaso";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      int i = 0;
      while (it.hasNext()) {
          if (i != 0){
            sb.append(" and ");
         }
         i++;
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"= '"+  e.getValue()+"'");
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolquestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Remolquestraspaso remolquestraspaso2 = new Remolquestraspaso(
         rs.getInt("idnumeraciontraspaso"),rs.getLong("idremolque"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getString("idold"),rs.getString("tipoidold"),rs.getString("id"),rs.getString("tipoid"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fechatraspaso"),rs.getDate("fecha"),rs.getString("username"));
            
            
       list.add(remolquestraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* Double fFunc(String funcion, String campo)
*/



public static Double func(String funcion, String campo) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from remolquestraspaso";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolquestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0.0;
}


/**
*
* Double func(String funcion, String campo,String where)
*/



public static Double func(String funcion, String campo, String where) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from remolquestraspaso where "+where +" ";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolquestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0.0;
}


/**
*
* count()
*/



public static Integer count() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from remolquestraspaso";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolquestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
   rs.beforeFirst();
   while (rs.next()) {
    x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0;
}


/**
*
* count(String sqlquery)
*/



public static Integer count(String sqlquery) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from remolquestraspaso where  " + sqlquery +"";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolquestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
   rs.beforeFirst();
   while (rs.next()) {
    x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0;
}


/**
*
* query()
*/

public static List<Remolquestraspaso> query(String query,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
        list = new ArrayList<Remolquestraspaso>();
  String sql = "select * from remolquestraspaso where " + query +"";
  if (query == null || query.equals("")) {
  return null;
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolquestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Remolquestraspaso remolquestraspaso2 = new Remolquestraspaso(
         rs.getInt("idnumeraciontraspaso"),rs.getLong("idremolque"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getString("idold"),rs.getString("tipoidold"),rs.getString("id"),rs.getString("tipoid"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fechatraspaso"),rs.getDate("fecha"),rs.getString("username"));
            
            
       list.add(remolquestraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* getListRecords()
*/

public static List<Remolquestraspaso> getListRecords(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
      list = new ArrayList<Remolquestraspaso>();
  String sql = "select * from remolquestraspaso";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      while (it.hasNext()) {
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"="+  e.getValue());
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "remolquestraspaso" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
       
        Remolquestraspaso remolquestraspaso2 = new Remolquestraspaso(
         rs.getInt("idnumeraciontraspaso"),rs.getLong("idremolque"),rs.getString("placa"),rs.getInt("idrecibo"),rs.getString("idold"),rs.getString("tipoidold"),rs.getString("id"),rs.getString("tipoid"),rs.getString("activo"),rs.getString("idmunicipio"),rs.getDate("fechatraspaso"),rs.getDate("fecha"),rs.getString("username"));
            
            
       list.add(remolquestraspaso2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
 }


}
